define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/withdraw/index' + location.search,
                    add_url: 'user/withdraw/add',
                    edit_url: 'user/withdraw/edit',
                    del_url: 'user/withdraw/del',
                    multi_url: 'user/withdraw/multi',
                    import_url: 'user/withdraw/import',
                    table: 'user_withdraw',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'avatar', title: __('Avatar'), events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false},
                        {field: 'alipay_name', title: __('Alipay_name'), operate: 'LIKE'},
                        {field: 'alipay_account', title: __('Alipay_account'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'money', title: __('Money'), operate:'BETWEEN'},
                        {field: 'true_money', title: __('True_money'), operate:'BETWEEN'},
                        {field: 'sxf_price', title: __('Sxf_price'), operate:'BETWEEN'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'des', title: __('Des'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'status', title: __('Status'), searchList: {"2":__('Status 2'),"1":__('Status 1'),"0":__('Status 0')}, formatter: Table.api.formatter.status},
                        {
                            field: 'buttons',
                            width: "120px",
                            title: __('操作'),
                            table: table,
                            events: Table.api.events.buttons,
                            buttons: [

                                {
                                    name: 'agree',
                                    text: __('支付宝通过'),
                                    title: __('支付宝通过'),
                                    classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                    icon: 'fa fa-check',
                                    url: 'user/withdraw/alipayAgree',
                                    confirm: '确认通过',
                                    visible:function(data){
                                        if(data.status!=0){
                                            return false;
                                        }
                                        return true;
                                    },
                                    success: function (data, ret) {
                                        Layer.alert(ret.msg);
                                        //如果需要阻止成功提示，则必须使用return false;
                                        //return false;
                                    },
                                    error: function (data, ret) {
                                        console.log(data, ret);
                                        Layer.alert(ret.msg);
                                        return false;
                                    }
                                }, {
                                    name: 'agree',
                                    text: __('线下通过'),
                                    title: __('线下通过'),
                                    classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                    icon: 'fa fa-check',
                                    url: 'user/withdraw/agree',
                                    confirm: '确认通过',
                                    visible:function(data){
                                        if(data.status!=0){
                                            return false;
                                        }
                                        return true
                                    },
                                    success: function (data, ret) {
                                        Layer.alert(ret.msg);
                                        //如果需要阻止成功提示，则必须使用return false;
                                        //return false;
                                    },
                                    error: function (data, ret) {
                                        console.log(data, ret);
                                        Layer.alert(ret.msg);
                                        return false;
                                    }
                                },
                                {
                                    name: 'bohui',
                                    text: __('驳回'),
                                    title: __('驳回'),
                                    classname: 'btn btn-xs  btn-warning btn-magic btn-ajax',
                                    icon: 'fa fa-close',
                                    url: 'user/withdraw/bohui',
                                    confirm: '确认驳回',
                                    visible:function(data){
                                        if(data.status!=0){
                                            return false;
                                        }
                                        return true
                                    },
                                    success: function (data, ret) {
                                        Layer.alert(ret.msg);
                                        //如果需要阻止成功提示，则必须使用return false;
                                        //return false;
                                    },
                                    error: function (data, ret) {
                                        console.log(data, ret);
                                        Layer.alert(ret.msg);
                                        return false;
                                    }
                                },

                            ],
                            formatter: Table.api.formatter.buttons
                        },
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
